/**
 * 主机编辑
 */
define(['module/component/views/FormView',
        'module/hostapp/action/HostAppAction',
        'module/hostapp/tools/tools',
        "text!module/hostapp/templates/HostEdit.html"],
	   function(FormView, hostAppAction, Tools, HostEditHtml){
		  return ngc.View.extend({
			  events: {
				'click #btnSubmit' : 'btnSubmitClick',
				'click #btnCancel' : 'btnCancelClick',
		      },
		      _form: function(){
			      return this.getView("#form_content");
			  },
			  btnSubmitClick: function(){
				  //获取当前表单数据
			      var rowData = this._form().getValues();
			      if(!this._form().valid()){
					  ngc.info("必填信息不完整！");
					  return;
				  }
			      if(this.options.type == "edit"){
			    	  rowData.id = this.options.rowData.id;
			      }
			      var sendData = {
			    		  type : this.options.type,
			    		  rowData : rowData
			      }
			      hostAppAction.editHost(sendData, function(data){
			    	  if(data.status == "SUCCESS"){
			    		  if(this.options.type == "edit"){
			    			  ngc.info("主机信息操作成功");
			    		  }else{
			    			  ngc.info("主机信息操作成功");
			    		  }
			    		  this.btnCancelClick();
			    	  }
			      }.bind(this));
			  },
			  btnCancelClick:function(){
				  this.trigger("editView", {});
			      this.popup.close();
			  },
			  render:function(){
				  this.$el.append(ngc.compile(HostEditHtml));
				  this.initWidget();
				  this._initForm();
			  },
			  _initForm: function(){
				  var _that = this;
				  var config_elements = 
					  [{
						  id: 'hostIp',
						  type : 'text',
						  label: '主机IP',
						  required:true,
						  rule : "描述:required",
					  }, {
						  id : 'hostType',
							type : 'select',
							label : '主机类型',
							enumCode : "hostType",
							required:true,
							rule : "描述:required",
					  }, {
						  id: 'hostAccount',
						  type : 'text',
						  label: '主机帐号',
					  }, {
						  id: 'hostPassword',
						  type : 'text',
						  label: '主机密码',
					  }, {
						  id : 'operateSystem',
						  type : 'text',
						  label : '操作系统',
					  }, {
						  id : 'cpu',
						  type : 'text',
						  label : 'CPU',
					  },{
						  id : 'memory',
						  type : 'text',
						  label : '内存大小',
					  },{
						  id : 'surplusMemory',
						  type : 'text',
						  label : '内存剩余大小',
					  }, {
				        	id: 'disk',
				        	type : 'text',
				        	label: '存储',
				        }, {
				        	id: 'surplusDisk',
				        	type : 'text',
				        	label: '剩余存储',
				        }, {
				        	id: 'location',
				        	type : 'text',
				        	label: '主机位置',
				        }, {
				        	id: 'responsibility',
				        	type : 'text',
				        	label: '责任人',
				        }, {
				        	id: 'tel',
				        	type : 'text',
				        	label: '联系电话',
//				        }, {
//				        	id: 'startDate',
//				        	type : 'date',
//				        	label: '启用时间',
//				        	format: 'yyyy-mm-dd'
				        }, {
				        	id: 'notes',
				        	type : 'text',
				        	label: '备注',
				        }];
				  	this.setView("#form_content", new FormView({
			    		config : {
							elements : config_elements,
							column: 2
						}
			    	}));
			    	this.getView("#form_content").on("viewRenderAfter", function() {
			    		if(this.options.type == "edit"){
			    			this._form().setValues(this.options.rowData);
			    			this._form().initValue("startDate", {value: this.options.rowData.startDate});
			    		}
					}.bind(this));
			  },
			  initWidget:function(){
		    	 this.$("#tabs").tabs({
					canClose:false,
					paging: false,
					autoResizable:true
				 });
			  },
			  afterRender: function(){
			  }
		  });
});